﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.DiaLy
{
    public partial class popThemQH : Form
    {
        public popThemQH()
        {
            InitializeComponent();
        }

        private void binCombo(ComboBox cb, DataTable dt, string name, string value, string option)
        {
            List<trangthai> list = new List<trangthai>();
            trangthai ls = null;
            ls = new trangthai();
            ls.name = option;
            ls.value = "0";
            list.Add(ls);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ls = new trangthai();
                    ls.name = dt.Rows[i][name].ToString();
                    ls.value = dt.Rows[i][value].ToString();
                    list.Add(ls);
                }
            }
            cb.DataSource = list;
            cb.DisplayMember = "name";
            cb.ValueMember = "value";
        }

        private void popThemQH_Load(object sender, EventArgs e)
        {
            //tinh thanh pho
            clTTP ttp = new clTTP();
            DataTable dtttp = ttp.getdata(1);
            binCombo(cbTinh, dtttp, "ten", "id", "<Chọn tỉnh/thành phố>");
        }

        public delegate void ThemQH(int outid);

        public ThemQH MyFuntion;

        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyFuntion != null)
            {
                Int16 matinh = Int16.Parse(cbTinh.SelectedValue.ToString());
                string tenhuyen = txtQuanHuyen.Text.ToString();
                Int16 vitri = Int16.Parse((txtVitri.Text.Trim() == "") ? "0" : txtVitri.Text.Trim());
                Int16 hienthi = Int16.Parse((checkHienthi.Checked) ? "1" : "0");
                string tenkhongdau = Querys.LocDau(txtQuanHuyen.Text.Trim()).ToLower();

                clQH adv = new clQH();
                int outid = adv.add(matinh, tenhuyen, vitri, hienthi,tenkhongdau);
                MyFuntion(outid);
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void panelheader_Paint(object sender, PaintEventArgs e)
        {

        }

        private void txtVitri_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void cbTinh_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void txtQuanHuyen_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
